﻿var vm = new Vue({
    el: '#app',
    data:function(){
        return{
            pagename:"追溯流程",
            common_fn:null,
            userinfo:null,

            teams:{},
            workShops:{},
            sysWarehouses:{},
            qcpProcess:{},

            reviewflowGraph : null,
            selmsg:{
                barcode:'',
                //true 向后追溯  false 向前追溯
                direction:'1'
            },

            // 追溯点详细信息列表
            node_detail_list : null,

            cardnoCompare : '',
            cardno : '',
            cardnoClone : '',

            nodeDetail_Dialog:false
        }
    },
    methods:{
        getreviewflow:function(){
            var self = this;
            self.cardnoClone = self.cardno;
            self.cardno = '';
            if(self.cardnoClone == ''){ 
                notify_timeOut('请输入追溯码','error');return
            }
            if(self.cardnoClone.indexOf('*')>=0){
                var arr = self.cardnoClone.split('*');
                self.cardnoClone = arr[arr.length-2];
            }
            self.selmsg.barcode = self.cardnoClone;
            var param = {
                barcode:self.selmsg.barcode,
                direction:self.selmsg.direction == '1'?false:true,
                user: self.userinfo.user,
                connectionId: 2,
                appName: "Mes",
                factory: self.common_fn.configInfo.factory
            }
            self.common_fn.invokeFun('TR_TraceBackBarcode',param,self.userinfo,function(response){
                if(response.resFlag == 0){
                    self.reviewflowGraph = response.result.roots;
                    createIframe();
                }else{
                    notify(response.errMsg,'error');
                }
            })
        }
    },
    created:function(){
        
    },
    mounted:function(){
        var self = this;
        self.common_fn = new common_fn();
        self.common_fn.init(function(){
            self.common_fn.UserInfo(function(response){
                if(response.user == null){
                    window.location.href = '../login.html?redirect=./reviewflow/reviewflow.html';
                }
                self.userinfo = response;
                self.common_fn.CheckFunction(self.userinfo,'mes','mes','TraceSearch','','','reviewflow',function(){})
                self.common_fn.queryObject("MesTeam",[],self.userinfo,function(res){
                    if(res.resFlag == 0){
                        for(var i=0;i<res.result.length;i++){
                            self.teams[res.result[i].id] = res.result[i].properties.name;
                        }
                    }else{
                        notify(response.errMsg,'error');
                    }
                })
                self.common_fn.queryObject("QcpWorkShop",[],self.userinfo,function(res){
                    if(res.resFlag == 0){
                        for(var i=0;i<res.result.length;i++){
                            self.workShops[res.result[i].id] = res.result[i].properties.name;
                        }
                    }else{
                        notify(response.errMsg,'error');
                    }
                })
                self.common_fn.queryObject("SysWarehouse",[],self.userinfo,function(res){
                    if(res.resFlag == 0){
                        for(var i=0;i<res.result.length;i++){
                            self.sysWarehouses[res.result[i].id] = res.result[i].properties.name;
                        }
                    }else{
                        notify(response.errMsg,'error');
                    }
                })
                self.common_fn.queryObject("QcpProcess",[],self.userinfo,function(res){
                    if(res.resFlag == 0){
                        for(var i=0;i<res.result.length;i++){
                            self.qcpProcess[res.result[i].id] = res.result[i].properties.name;
                        }
                        eval("sessionStorage.qcpProcess='"+encodeURI(JSON.stringify(self.qcpProcess))+"'");
                    }else{
                        notify(response.errMsg,'error');
                    }
                })
                window.initLoadMeta();
            })
        });
        self.keyDown = function(e){
            var keycode = window.event?e.keyCode:e.which;
            if(keycode == 13){
                self.cardno = self.cardnoCompare;
                self.cardnoCompare = ''
                self.getreviewflow();
            }
        }
        
        $(document).keypress(function (e) {
            var keycode = window.event?e.keyCode:e.which;
            if(keycode!==13){
                //只读取字母和数字键
                if(48<=keycode && keycode<=57 || 65<=keycode && keycode<=90 ){
                    self.cardnoCompare += (keycode - 48);
                }
            }
        });
    }
})
